
<div class="pProduct-pupHead clearfix">
    <div class="pic">
        <img src="{$goodsInfo.original_img}">
    </div>
    <div class="name">
        {$goodsInfo.goods_name}
    </div>
    <div class="price clearfix">
        <span class="sale">￥<strong id="shop_price">{$goodsInfo.shop_price}</strong></span>
    </div>
</div>
<!--规格-->
<div class="pProduct-pupSpec">
    <div class="dt">
        口味
    </div>
    <div class="dd clearfix">
        <!--<a href="javascript:;" class="item selected" onclick="is_default()">默认</a>-->
        <foreach name="$goodsInfo.spec" item="v1" key="k1">
            <foreach name="v1" item="v2" key="k2">
                <a href="javascript:;" class="item" data-id="{$v2.item_id}">{$v2.item}</a>
            </foreach>
        </foreach>
    </div>
</div>

<!--规格 End-->
<!--数量-->
<div class="pProduct-pupAmount clearfix">
    <div class="dt">
        数量
    </div>
    <div class="dd fr">
        <div class="quantity clearfix">
            <a class="decrease iconfont" id="reduce">&#xe6fd;</a>
            <input type="tel" class="inpt" size="4" value="1" id="num" data-spec-id="" data-id="{$goodsInfo.goods_id}" readonly>
            <a class="increase iconfont" id="add">&#xe71b;</a>
        </div>
    </div>
</div>
<!--数量 End-->
<div class="pProduct-pupButton">
    <a href="javascript:;" class="btn" onclick="add_cart()" >确   定</a>
</div>


<script type="text/javascript">
    //获取规格价格
    function goods_price(spec_goods_price,spec_key){
        if(spec_goods_price != null && spec_goods_price !=''){
            var goods_price = spec_goods_price[spec_key]['price'];
            var store_count = spec_goods_price[spec_key]['store_count'];
            // console.log(spec_key);
        }
        $('#shop_price').html(goods_price);
        $('#num').attr('data-max',store_count);
        $('#num').attr('data-spec-id',spec_key);
    }

    $(function () {
        $(".pProduct-pupSpec .dd .item").click(function(){
            $(this).toggleClass("selected").siblings().removeClass("selected");
            var spec_key = $(this).attr('data-id');
            goods_price({$goodsInfo.spec_goods_price},spec_key);
        });
        //数量增加
        $("#add").click(function () {
            var goods_store_count = "{$goodsInfo.store_count}"
            var eleInput = $("#num");
            var num_count = eleInput.val();//获取目前的数量
            if (parseInt(num_count) < parseInt(goods_store_count)){
                eleInput.val(parseInt(eleInput.val()) + 1);
            }
            //console.log($("#num").val());
        });
        //数量减少
        $("#reduce").click(function () {
            var goods_store_count = "{$goodsInfo.store_count}"
            var eleInput = $("#num");
            var num_count = eleInput.val();//获取目前的数量

            if (num_count >= 2){
                eleInput.val(parseInt(eleInput.val()) - 1); //数量+1
            }
        });
    });

    function add_cart(){
        var _this = $('#num');
        var num = _this.val(); //数量
        var goods_id = _this.attr('data-id'); //商品id
        var spec_key = _this.attr('data-spec-id'); //规格id
        $.ajax({
            type : "POST",
            url:"/Home/Cart/ajaxAddCart2.html",
            data : {goods_id:goods_id,goods_num:num,goods_spec:spec_key},// 你的formid 搜索表单 序列化提交
            dataType:'json',
            success: function(data){
                if(data.status != 200){
                    layer.msg(data.msg,{icon:2,time:2000},function(){if(data.url){ window.location.href = data.url;}});
                    return false;
                }else{
                    layer.msg(data.msg,{icon:1,time:2000},function(){if(data.url){ window.location.href = data.url;}});
                }

            }
        });
    }
</script>